package com.dys.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: 疾风
 * @ClassName: Servlet06
 * @Description: 基于注解模式开发Servlet
 * @CreateDate: 2024/09/20
 * @Version: v1.0.0
 */
@WebServlet(urlPatterns = {"/servlet06.do", "/b.do", "/c.do", "/d.do"},
        loadOnStartup = 6,
        initParams = {@WebInitParam(name = "brand", value = "华为"), @WebInitParam(name = "screen", value = "京东方")})
public class Servlet06 extends HttpServlet {
    public Servlet06() {
        System.out.println("Servlet06实例化......");
    }

    @Override
    public void init() throws ServletException {
        System.out.println("Servlet06初始化......");
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // url匹配
        System.out.println("走Servlet06的service方法......");
        System.out.println("匹配上了");
        ServletConfig servletConfig = this.getServletConfig();
        System.out.println("初始化品牌：" + servletConfig.getInitParameter("brand"));
        System.out.println("初始化屏幕：" + servletConfig.getInitParameter("screen"));
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().write("匹配成功!");
    }

    @Override
    public void destroy() {
        System.out.println("Servlet06销毁......");
    }
}
